package com.ar4j.bench.hibernate.domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.ar4j.bench.common.domain.IProduct;

@Entity
@Table(name = "PRODUCT")
public class Product implements IProduct {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  
  @ManyToOne
  @JoinColumn(name = "CATEGORY_ID")
  private Category category;
  
  private String name;
  private String image;
  private String description;
  
  @OneToMany(mappedBy = "product", cascade = CascadeType.ALL)
  private Set<Item> items;
  
  public Long getId() {
    return id;
  }
  
  public void setId(Long id) {
    this.id = id;
  }
  
  public Long getCategoryId() {
    return category.getId();
  }
  
  public void setCategoryId(Long categoryId) {
    throw new UnsupportedOperationException("Cannot set ID directory, user setCategory instead");
  }
  
  public Category getCategory() {
    return category;
  }

  public void setCategory(Category category) {
    this.category = category;
  }

  public String getName() {
    return name;
  }
  
  public void setName(String name) {
    this.name = name;
  }
  
  public String getImage() {
    return image;
  }
  
  public void setImage(String image) {
    this.image = image;
  }
  
  public String getDescription() {
    return description;
  }
  
  public void setDescription(String description) {
    this.description = description;
  }

  public Set<Item> getItems() {
    return items;
  }

  public void setItems(Set<Item> items) {
    this.items = items;
  }
  
}
